<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目档案编号">
              <j-input placeholder="请输入项目档案编号" v-model="queryParam.finalNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.projectName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同总额（元）">
              <a-input-number  :max="99999999" :min="0" :precision="2" v-model="queryParam.contractTotalMoney_begin" placeholder="最小金额"
                               style="width:105px;margin-right: 5px"/>
              —
              <a-input-number :max="99999999" :min="0" :precision="2" v-model="queryParam.contractTotalMoney_end" placeholder="最大金额"
                              style="width: 105px;margin-left: 5px"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="应收款总额（元）">
                <a-input-number  :max="99999999" :min="0"   v-model="queryParam.receivablesPaymentMoney_begin" placeholder="最小金额"
                                style="width:105px;margin-right: 5px"/>
                —
                <a-input-number :max="99999999" :min="0"   v-model="queryParam.receivablesPaymentMoney_end" placeholder="最大金额"
                                style="width: 105px;margin-left: 5px"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="实收款总额（元）">
                <a-input-number  :max="99999999" :min="0"  v-model="queryParam.realCollectionPaymentMoney_begin" placeholder="最小金额"
                                style="width:105px;margin-right: 5px"/>
                —
                <a-input-number :max="99999999" :min="0"  v-model="queryParam.realCollectionPaymentMoney_end" placeholder="最大金额"
                                style="width: 105px;margin-left: 5px"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="最近汇款时间" :labelCol="labelCol">
                <a-range-picker
                  showTime
                  format="YYYY-MM-DD HH:mm:ss"
                  :placeholder="['开始时间', '结束时间']"
                  v-model="lastPaymentDateRange"
                  @change="(dates, dateStrs) => { queryParam.lastPaymentTime_begin = dateStrs[0]; queryParam.lastPaymentTime_end = dateStrs[1] }"
                  style="width: 100%"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="状态">
                <j-dict-select-tag style="width: 300px;" placeholder="请选择状态" v-model="queryParam.paymentEditStatus" dictCode="edit_status"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="handleReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator" style="margin-bottom: 28px">
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12">
                    <a-checkbox :value="item.dataIndex">
                      <!-- {{ item.title }} -->
                      <ellipsis :length="15">{{item.title}}</ellipsis>
                      </a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;">
          <a-icon type="setting" :style="iconStyle"/>
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="contractId"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
           <a  @click="handleEdit(record)" v-if="record.paymentEditStatus === '1'">
               编制
            </a>
          <a-popconfirm title="确定提交吗?" @confirm="() => executeSubmit(record.contractId)" v-if="record.paymentEditStatus === '1'">
             <a>  提交</a>
          </a-popconfirm>
           <a  @click="handleViews(record)">
               查看
            </a>
        </span>
        <a slot="projectName" slot-scope="text, record" @click="handleViews(record)">{{ text }}</a>
      </a-table>
    </div>
    <erp-progress-payment-modal ref="modalForm" @ok="modalFormOk"></erp-progress-payment-modal>
    <erp-progress-payment-views-modal  ref="paymentView" @ok="modalFormOk"></erp-progress-payment-views-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import Area from '@/components/_util/Area'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import ErpProgressPaymentModal from './modules/ErpProgressPaymentModal';
import ErpProgressPaymentViewsModal from './modules/ErpProgressPaymentViewsModal';
import { getAction, putAction } from '@api/manage';
import Ellipsis from '@/components/Ellipsis'

export default {
  name: 'ErpProgressPaymentList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    ErpProgressPaymentModal,
    ErpProgressPaymentViewsModal,
    Ellipsis
  },
  data() {
    return {
      description: '收款进度管理页面',
      queryParam: {
        contractType: '1'
      },
      //表头
      columns: [],
      //列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目档案编号',
          align: 'center',
          dataIndex: 'finalNo',
          width:170,
          ellipsis: true,
        },
        {
          title: '合同名称',
          align: 'center',
          dataIndex: 'contractName',
          width:500,
          ellipsis: true,
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'projectName',
          width:500,
          ellipsis: true,
          scopedSlots: { customRender: 'projectName' }
        },
        {
          title: '合同总额（元）',
          align: 'center',
          dataIndex: 'contractTotalMoney',
          width:130,
          ellipsis: true,
        },
        {
          title: '应收款总额（元）',
          align: 'center',
          dataIndex: 'receivablesPaymentMoney',
          width:130,
          ellipsis: true,
        },
        {
          title: '实收款总额（元）',
          align: 'center',
          dataIndex: 'realCollectionPaymentMoney',
          width:130,
          ellipsis: true,
        },
        {
          title: '扣款总额（元）',
          align: 'center',
          dataIndex: 'deductMoney',
          width:130,
          ellipsis: true,
        },
        {
          title: '最近更新时间',
          align: 'center',
          dataIndex: 'lastPaymentTime',
          width:130,
          ellipsis: true,
        },
        {
          title: '编制状态',
          align: 'center',
          dataIndex: 'paymentEditStatus_dictText',
          width:130,
          ellipsis: true,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          fixed:"right",
          width:147,
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
        }
      ],
      url: {
        list: '/api/erp/progress/erpProgressPayment/list',
        edit: '/api/erp/omc/contractmanager/erpOmcContractManagerFinal/edit',
        delete: '/api/erp/omc/project/erpOmcProject/delete',
        deleteBatch: '/api/erp/omc/project/erpOmcProject/deleteBatch',
        exportXlsUrl: '/api/erp/omc/project/erpOmcProject/exportXls',
        importExcelUrl: 'api/erp/omc/project/erpOmcProject/importExcel',
      },
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
      isorter: {
        column: '',
        order: ''
      },
      lastPaymentDateRange: [],
    }
  },
  searchReset() {
    this.queryParam = {}
    this.queryParam.contractType = '1'
    this.loadData(1)
  },
  created() {
    this.pcaData = new Area()
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    //提交
    executeSubmit: function (contractId) {
      console.log('contractId', contractId)
      if (!this.url.edit) {
        this.$message.error('请设置url.edit属性!')
        return
      }
      var that = this
      getAction('/api/erp/progress/erpProgressPayment/validateSubmitByContractId',
          { contractId: contractId }).then((res) => {
        if (res.success) {
          putAction(that.url.edit, {
            id: contractId,
            paymentEditStatus: '2'
          }).then(res => {
            if (res.success) {
              that.$message.success(res.message)
              that.loadData()
            } else {
              that.$message.warning(res.message)
            }
          })
        } else {
          that.$message.warning(res.message)
        }
      }).catch((e) => {
        console.error(e)
        that.$message.warning(res.message)
      }).finally(() => {
        this.loading = false
        this.tableLoading = false
      })
    },
    handleViews: function (record) {
      this.$refs.paymentView.edit(record)
      this.$refs.paymentView.title = '查看'
      this.$refs.paymentView.disableSubmit = true
    },
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'year', text: '归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'string', value: 'accountAdmin', text: '台账管理员', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectAddress', text: '项目地址', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'outline', text: '项目内容概要', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'prepareProjectId',
        text: '预立项',
        dictCode: 'erp_omc_prepare_project,mc,id'
      })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectNo', text: '项目档案编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectType', text: '项目类型', dictCode: 'xmlx_type' })
      fieldList.push({ type: 'string', value: 'ownerUnit', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handler', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handingDepartmernt', text: '经办部门', dictCode: 'departments' })
      fieldList.push({ type: 'string', value: 'teamName', text: '经营团队', dictCode: 'teams' })
      fieldList.push({ type: 'string', value: 'undertaker', text: '承接人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'projectEstablishDate', text: '立项日期' })
      fieldList.push({ type: 'string', value: 'signUnit', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'estimatedContractAmount', text: '预计合同额（元）', dictCode: '' })
      fieldList.push({ type: 'string', value: 'estimatedContractcapitalChineseAmount', text: '预计合同额大写', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'isEnvironmentalAssessmentProject',
        text: '是否环评项目',
        dictCode: 'YES_OR_NO'
      })
      fieldList.push({ type: 'string', value: 'contacts', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactTel', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectSource', text: '项目来源', dictCode: 'xmly_type' })
      fieldList.push({ type: 'string', value: 'status', text: '流程状态', dictCode: 'project_status' })
      fieldList.push({ type: 'string', value: 'attachment', text: '相关附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'isPrepareEstablish', text: '是否预立项', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'string', value: 'isBidding', text: '是否招投标', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'Text', value: 'establishReason', text: '立项事由及说明', dictCode: '' })
      fieldList.push({ type: 'pca', value: 'areaCode', text: '县区编码' })
      this.superFieldList = fieldList
    },
    handleReset() {
      this.lastPaymentDateRange = [];
      this.queryParam = {};
      this.queryParam.contractType = '1'
      this.loadData(1);
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
